<template>
  <div class="page-box   ">
    <p class="title-label mb10">{{ jdsfdfs }}--周期卡列表</p>
    <div>
      <div class="display-flex">
        <div class="zxczxertert">
          <n-input v-model:value="jnxsdfd.card_template_name" type="text" placeholder="卡片名称" />
        </div>
        <div class="ml20">
          <n-button type="info" @click="initsd"> 搜索 </n-button>
          <n-button type="info" @click="hf('addka')" class="ml20"> +添加 </n-button>
        </div>
      </div>

    </div>
    <n-table :single-line="false" class="mt20">
      <thead>
        <tr>
          <th>id</th>
          <th>封面</th>
          <th>名称</th>
          <th>结算方式</th>
          <th>售卖时间</th>
          <th>状态</th>

          <!-- <th>门店认证状态</th> -->
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="sd in shopInfos">
          <td width="100">{{ sd.cardTemplateId }}</td>
          <td width="60">

            <n-image width="50" :src="sd.sptupse" v-if="sd.sptupse" />
            <n-image width="50" :src="sd.imageUrlList[0]" v-else />
          </td>
          <td>
            {{ sd.cardTemplateName }}
          </td>
          <td>

            {{ jzxcsdfdb(sd.settleType) }}
          </td>
          <td width="350">
            <span v-if="sd.smshie">{{ sd.smshie }}</span>

            <span v-else> {{ sd.saleInfo.salableStartTime }}~ {{ sd.saleInfo.salableEndTime }}</span>
          </td>

          <td width="200">
            <span v-if="sd.cardTemplateStatus">
              {{ jzxcsdfd(sd.cardTemplateStatus) }}
            </span>
            <div v-else class="ls sz">

              <n-button type="info" quaternary @click="initsd" :loading="dsfdsfrttrt">
                {{ sd.isdrt }} <span>点击刷新状态</span>
              </n-button>
            </div>
          </td>
          <td width="200" v-if="!sd.isdrt">
            <n-button type="info" quaternary @click="hf('bjbjzqka', sd)"> 编辑 </n-button>
            <n-button type="error" quaternary @click="xiazai(sd, 'STOP')" :loading="zxcxzrtret"
              v-if="sd.cardTemplateStatus == 'PUBLISHED'"> 下架 </n-button>
            <n-button type="success" quaternary @click="xiazai(sd, 'STOP')" :loading="zxcxzrtret"
              v-if="sd.cardTemplateStatus == 'PUBLISH'"> 上架 </n-button>
          </td>

        </tr>

      </tbody>
    </n-table>
    <!-- <div class="mt20 z9 fz12">
      新增或修改可能不会立即生效，需要等待10秒-5分钟同步
    </div> -->
  </div>
</template>
<script lang='ts' setup>
import { ref } from 'vue'
import { dxget, hf, dialog, dxpost } from "../../util/index";
const jdsfdfs = localStorage.sjmcsee
const shopInfos = ref([])
const dsfdsfrttrt = ref()
const jnxsdfd = ref({
  card_template_name: ""
})
const zxcxzrtret = ref(false)
if (!localStorage.app_auth_token) {
  hf('shangjiagl')
}
const zhjhsd = [
  { label: '已发布', value: 'PUBLISHED' },
  { label: '审核中', value: 'REVIEWING' },
  { label: '审核失败', value: 'REJECTED' },
  { label: '已下架', value: 'DELISTING' },
  { label: '已冻结', value: 'FREEZING' },
  { label: '已过期', value: 'EXPIRED' },

]
const jnxdfd = [
  { label: '统一收款', value: '1' },
  { label: '分店结算', value: '2' },
]
const jzxcsdfd = (valus) => {
  return zhjhsd.filter(a => a.value == valus)[0].label
}
const jzxcsdfdb = (valus) => {
  try {

    return jnxdfd.filter(a => a.value == valus)[0].label
  } catch (e) {

  }
}
const initsd = async () => {
  dsfdsfrttrt.value = true
  const { data } = await dxget('meirong/wantu/getList', jnxsdfd.value)
  shopInfos.value = data.content

  try {
    const hnxdr = JSON.parse(localStorage.zouqika)
    let jnxcdf = true
    shopInfos.value.map(a => {
      if (a.cardTemplateName == hnxdr.cardTemplateName) {
        localStorage.zouqika = null
        jnxcdf = false
      }
    })
    if (localStorage.zouqika && localStorage.zouqika != 'null') {
      shopInfos.value.unshift(hnxdr)
    }

  } catch (e) {

  }
  dsfdsfrttrt.value = false
}
initsd()
const shanchuser = async (data) => {
  const res = await dialog("确认删除吗？");
  if (res == 1) {
    //等于1为确认删除了
    const ret = await dxpost('meirong/wantu/sanchudp', { shopId: data.shopId })
    window.$message.success('删除成功！')
    initsd()
  }
}
const xiazai = async (sd, operateStatus) => {
  zxcxzrtret.value = true
  const { data } = await dxpost('meirong/wantu/xiugmodify', { cardTemplateId: sd.cardTemplateId, operateStatus })
  console.log(data);
  zxcxzrtret.value = false
  if (data.code != 10000) {
    window.$message.error(data.subMsg)
    return
  }


  initsd()
}
</script>
<style scoped>
.zxczxertert {
  width: 300px;
}
</style>